//package cn.base.web.gateway.exception;
//
//import com.bjtxra.gateway.utils.WebFluxUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
//import org.springframework.cloud.gateway.support.NotFoundException;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.annotation.Order;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.MediaType;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.web.reactive.function.BodyInserters;
//import org.springframework.web.reactive.function.server.ServerResponse;
//import org.springframework.web.server.ResponseStatusException;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
///**
// * 网关统一异常处理
// *
// * @author develop
// */
//@Slf4j
//@Order(-1)
//@Component
//public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
//
//    @Override
//    public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
//        ServerHttpResponse response = exchange.getResponse();
//
//        if (exchange.getResponse().isCommitted()) {
//            return Mono.error(ex);
//        }
//
//        String msg;
//
//        if (ex instanceof NotFoundException) {
//            msg = "服务未找到";
//        } else if (ex instanceof ResponseStatusException) {
//            ResponseStatusException responseStatusException = (ResponseStatusException) ex;
//            msg = responseStatusException.getMessage();
//        } else {
//            msg = "内部服务器错误";
//        }
//        return ServerResponse.status(HttpStatus.OK)
//                .contentType(MediaType.APPLICATION_JSON_UTF8)
//                .body(BodyInserters.fromObject(null)).then();
//    }
//}
